package com.ellricky.baselib.ui.reserve;


import android.view.View;
import android.widget.TextView;

import com.ellricky.baselib.R;
import com.ellricky.baselib.entity.reserve.CtReserveDetailEntity;
import com.ellricky.baselib.http.callback.ECallback;
import com.ellricky.baselib.ui.base.BaseDetailActivity;
import com.ellricky.baselib.widget.DetailItemView;
import com.flyco.roundview.RoundTextView;

import static com.ellricky.baselib.http.Api.API_RESERVE_AUDIT;
import static com.ellricky.baselib.http.Api.API_RESERVE_DETAIL;

public class ReserveDetailActivity extends BaseDetailActivity {

    private TextView tvName;
    private DetailItemView tvSex;
    private DetailItemView tvBirthDay;
    private DetailItemView tvOrderTime;
    private DetailItemView tvSchoolArea;
    private DetailItemView tvContact;
    private DetailItemView tvCtName;
    private DetailItemView tvPdName;
    private DetailItemView tvPdTime;

    private RoundTextView btnAudit;
    private TextView tvAudited;

    @Override
    protected int getChildContentLayout() {
        return R.layout.base_activity_reserve_detail;
    }

    @Override
    public void initUIView() {
        super.initUIView();
        mTvTitle.setText(R.string.base_order_detail);

        tvName = findViewById(R.id.tvName);
        tvSex = findViewById(R.id.tvSex);
        tvBirthDay = findViewById(R.id.tvBirthDay);
        tvOrderTime = findViewById(R.id.tvOrderTime);
        tvSchoolArea = findViewById(R.id.tvSchoolArea);
        tvContact = findViewById(R.id.tvContact);

        tvCtName = findViewById(R.id.tvCtName);
        tvPdName = findViewById(R.id.tvPdName);
        tvPdTime = findViewById(R.id.tvPdTime);


        btnAudit = findViewById(R.id.btnAudit);
        tvAudited = findViewById(R.id.tvAudited);

        btnAudit.setOnClickListener(this);
        loadDetailData(id);
    }

    @Override
    protected void onClickView(View v) {
        super.onClickView(v);
        if (v == btnAudit) mPresenter.sendBackRequest(API_RESERVE_AUDIT, id);
    }


    private void loadDetailData(String id) {
        mPresenter.loadDetail(API_RESERVE_DETAIL, id, new ECallback<CtReserveDetailEntity> (this) {
            @Override
            public void onSuccess(CtReserveDetailEntity data, String msg) {
                tvName.setText(data.getName());

                tvSex.setValue(data.getSexName());
                tvBirthDay.setValue(data.getBirthday());
                tvOrderTime.setValue(data.getAppointMarketDate());
                tvSchoolArea.setValue(data.getAreaName());
                tvContact.setValue(data.getTel());

                tvCtName.setValue(data.getMarkerName());
                tvPdName.setValue(data.getApproveName());
                tvPdTime.setValue(data.getAppointDate());


                if (data.hadPk()){
                    tvAudited.setVisibility(View.VISIBLE);
                    tvAudited.setText(data.getAppointStatusName());
                }else{
                    btnAudit.setVisibility(View.VISIBLE);
                }
            }
        });
    }


}